<!-- ERP-仓库看板 -->
<template>
	<view class="boardWrap">
		<!-- 快捷菜单 -->
		<view class="commonBox">
			<view class="commonBox-title">
				<view class="commonBox-title-left">
					<text>快捷发起</text>
				</view>
				<view class="commonBox-title-right">
					<uni-icons fontFamily="CustomFontPlatform" :size="18" color="#51d0d0"
						@click="showPopUp('menuConfig')">{{'\ue657'}}</uni-icons>
				</view>
			</view>
			<view class="commonBox-content">
				<swiper :indicator-dots="true" class="swiper">
					<swiper-item>
						<u-grid col="4">
							<u-grid-item
								:customStyle="{paddingTop:'10px',borderRadius:'5px',background:'linear-gradient(to bottom right, #F6F6F6, #FFFFFF)'}"
								v-for="(menu, menuIndex) in shortcuts.filter((item,index)=>index<8)" :index="menuIndex"
								:key="menuIndex" @click="checkOutMenu(menu)">
								<uni-icons v-if="menu.CustomFont && menu.PIC_PH" :fontFamily="menu.CustomFont"
									:size="22" :color="menu.AP_Colour">{{ $utils.toUniCode(menu.PIC_PH) }}</uni-icons>
								<uni-icons v-else fontFamily="CustomFontPlatform" :size="22"
									color="#3ace4b">{{ $utils.toUniCode('&#xe62c;') }}</uni-icons>
								<text class="grid-text">{{ menu.APFunName }}</text>
							</u-grid-item>
						</u-grid>
					</swiper-item>
					<swiper-item v-if="shortcuts.length>8">
						<u-grid col="4">
							<u-grid-item
								:customStyle="{paddingTop:'10px',borderRadius:'5px',background:'linear-gradient(to bottom right, #F6F6F6, #FFFFFF)'}"
								v-for="(menu, menuIndex) in shortcuts.filter((item,index)=>index>7)" :index="menuIndex"
								:key="menuIndex" @click="checkOutMenu(menu)">
								<uni-icons v-if="menu.CustomFont && menu.PIC_PH" :fontFamily="menu.CustomFont"
									:size="22" :color="menu.AP_Colour">{{ $utils.toUniCode(menu.PIC_PH) }}</uni-icons>
								<uni-icons v-else fontFamily="CustomFontPlatform" :size="22"
									color="#3ace4b">{{ $utils.toUniCode('&#xe62c;') }}</uni-icons>
								<text class="grid-text">{{ menu.APFunName }}</text>
							</u-grid-item>
						</u-grid>
					</swiper-item>
				</swiper>
			</view>
		</view>

		<view class="commonBox">
			<view class="commonBox-title">
				<view class="commonBox-title-left">
					<u-tabs lineColor="#51d0d0"
						:activeStyle="{color:'#51d0d0',fontWeight:'500',transform:'scale(1.05)'}"
						:current="waitActiveCurrent" :list="todoCondition" @change="item=>switchTab('TODO',item)">
					</u-tabs>
				</view>
				<view class="commonBox-title-right">
				</view>
			</view>
			<view class="commonBox-content">
				<view class="scrollWrap">
					<view v-for="(item,index) in waitDataShow" @click="handleClick_wait(item)" :index="index"
						:key="index" class="scrollWrap-item">
						<view class="todoTop">
							<uni-icons fontFamily="CustomFontPlatform" :size="18"
								color="#3ace4b">{{ $utils.toUniCode('&#xe62c;') }}</uni-icons>
							<text class="todoTop-text">{{item.Num}}</text>
						</view>
						<view class="todoBot">
							<text>{{item.name}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="commonBox">
			<view class="commonBox-title">
				<view class="commonBox-title-left">
					<text>实时数据</text>
				</view>
				<view class="commonBox-title-right">
					<u-tabs lineColor="#51d0d0"
						:activeStyle="{color:'#51d0d0',fontWeight:'500',transform:'scale(1.05)'}" :list="realCondition"
						@change="item=>switchTab('REALTIME',item)">
					</u-tabs>
				</view>
			</view>
			<view class="commonBox-content">
				<view class="scrollWrap">
					<view v-for="(item,index) in realTimeData" :index="index" :key="index" class="scrollWrap-item">
						<view class="rtTop">
							<text class="rtTop-left">仓</text>
							<text class="rtTop-right">{{item.Qty}}</text>
						</view>
						<view class="rtBot">
							<text>{{item.name}}</text>
							<text class="rtBot-right"><text style="color:#c9283a;">{{item.Num}}</text>单</text>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="commonBox">
			<view class="commonBox-title">
				<view class="commonBox-title-left">
					<text>出入库数量</text>
				</view>
				<view class="commonBox-title-right">
					<u-tabs lineColor="#51d0d0"
						:activeStyle="{color:'#51d0d0',fontWeight:'500',transform:'scale(1.05)'}" :list="saleCondition"
						@change="item=>switchTab('SALE',item)">
					</u-tabs>
				</view>
			</view>
			<view class="commonBox-content">
				<view class="charts-box">
					<qiun-data-charts type="column" :opts="opts" :ontouch="true"
						:chartData="chart1Data"></qiun-data-charts>
				</view>
			</view>
		</view>

		<view class="commonBox">
			<view class="commonBox-title">
				<view class="commonBox-title-left">
					<text>库龄占比</text>
				</view>
				<view class="commonBox-title-right">
					<!-- <u-tabs :list="propCondition" @change="item=>switchTab('PROP',item)">
					</u-tabs> -->
				</view>
			</view>
			<view class="commonBox-content">
				<view class="chart-box">
					<!-- <qiun-data-charts type="pie" :chartData="chart2Data"></qiun-data-charts> -->
					<qiun-data-charts type="ring" :opts="optsRing" :chartData="chart2Data" />
				</view>
			</view>
		</view>

		<u-popup :show="showMenuCfg" mode="bottom" @close="closePopUp('menuConfig')">
			<view class="shortcut">
				<u-navbar :fixed="false" title="快捷发起" :autoBack="false" leftIcon="" :safeAreaInsetTop="false"
					leftIconColor="#fff" style="width: 100%;">
					<view class="u-nav-slot" slot="left">
						<view style="display: flex;justify-content: center;align-items: center;" @click="saveShortcut">
							<uni-icons color="#fff" type="gear" size="30"></uni-icons>
							<text style="margin-left: 5px;color: #ffffff;">应用设置</text>
						</view>
					</view>
					<view class="u-nav-slot" slot="right">
						<uni-icons color="#fff" type="close" size="30" @click="closePopUp('menuConfig')"></uni-icons>
					</view>
				</u-navbar>
				<view class="shortcut-content">
					<view class="left_wrap">
						<view class="leftItem" :class="treeTypeIdx==index ? 'on' : ''"
							v-for="(treeType,index) in module.treeTypes" @click="changeTreeType(treeType,index)">
							<text>{{treeType.treeTypeName}}</text>
							<u-badge style="margin-left: 2px;"
								:value="treeType.pages.filter(item=>item.IsChecked).length" max="9" :showZero="true"
								bgColor="#c9283a" color="#ffffff"></u-badge>
						</view>
					</view>
					<view class="right_wrap">
						<u-cell v-for="(page,index) in selectedTreeType.pages" @click="toggleShortcut(page)">
							<view style="display: flex;justify-content: flex-start;align-items: center;" slot="title">
								<!-- <uni-icons :fontFamily="page.CustomFont" :size="22"
									:color="page.AP_Colour">{{ $utils.toUniCode(page.PIC_PH) }}</uni-icons> -->
								<uni-icons fontFamily="CustomFontPlatform" :size="22"
									color="#3ace4b">{{ $utils.toUniCode('&#xe62c;') }}</uni-icons>
								<text class="rightItem">{{page.APFunName}}</text>
							</view>
							<view slot="right-icon">
								<checkbox :checked="page.IsChecked" :disabled="page.IsShortcut"
									activeBackgroundColor="#51d0d0" activeBorderColor="#51d0d0"></checkbox>
							</view>
						</u-cell>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showMenuCfg: false,
				maxMenus: 16, // 最大可设置快捷菜单数量(3行)
				module: {},
				shortcuts: [], // 已配置全部快捷菜单(默认+自定义)
				treeTypeIdx: 0,
				selectedTreeType: {},
				currModuleID: 1, // 当前模块ID
				currBoardID: 12, // 当前看板ID
				waitDataShow: [],
				realTimeData: [], // 实时数据
				chart1Data: {},
				chart2Data: {},
				waitActiveCurrent: 0,
				todoCondition: [{
					name: '待办'
				}, {
					name: '待审核'
				}],
				realCondition: [{
					name: '本日'
				}, {
					name: '本月'
				}],
				saleCondition: [{
					name: '本周'
				}, {
					name: '本月'
				}, {
					name: '本年'
				}], // 销售切换条件
				propCondition: [{
					name: '本周'
				}, {
					name: '本月'
				}, {
					name: '本年'
				}],
				opts: {
					touchMoveLimit: 24,
					enableScroll: true,
					xAxis: {
						disableGrid: true,
						scrollShow: true,
						itemCount: 4
					}
				},
				optsRing: {
					padding: [5, 5, 5, 5],
					enableScroll: false,
					legend: {
						show: true,
						position: "left",
						lineHeight: 25
					},
					title: {
						name: "",
					},
					subtitle: {
						name: "",
					}
				}
			}
		},
		created() {
			let that = this;
			setTimeout(() => {
				that.initShortcut();
				that.initTabs();
			}, 200)
		},
		methods: {
			initModule(module, menu) {
				let that = this;

				// 发起请求获取模块页面数据
				this.Request.request('getAPPModulePages', {
					UserID: this.$store.state.UserInfo.UserID,
					APPType: module.ModuleID,
				}, (ret) => {
					if (ret.status === 200) {
						const {
							ds: data,
							ds1
						} = ret.data;

						// 使用 Map 预处理 ds1，以 APPFunID 为键
						const ds1Map = new Map();
						ds1.forEach(row => {
							if (!ds1Map.has(row.APPFunID)) {
								ds1Map.set(row.APPFunID, []);
							}
							ds1Map.get(row.APPFunID).push(row);
						});

						// 组织并排序数据
						let organizedData = that.organizeByTreeTypeName(data, ds1Map)
							.sort((a, b) => a.TreeType - b.TreeType);

						// 提取 TabbarData 和 workspaceData
						const TabbarData = [];
						const workspaceData = [];
						organizedData.forEach(item => {
							item.Node.forEach(row => {
								if (row.IsTabbar) {
									TabbarData.push(row);
								} else {
									workspaceData.push(row);
								}
							});
						});
						// 对结果进行排序
						TabbarData.sort((a, b) => a.APFunCode - b.APFunCode);
						workspaceData.sort((a, b) => a.APFunCode - b.APFunCode);

						this.TabbarData = TabbarData;
						this.workspaceData = workspaceData;

					}
				}, (err) => {
					// 处理错误
				});
			},
			organizeByTreeTypeName(arr, ds1Map) {
				// 创建一个 Map 以按 TreeTypeName 分组数据
				const groupedData = new Map();

				arr.forEach(item => {
					const {
						TreeTypeName,
						TreeType,
						appType,
						APPFunID
					} = item; // 解构赋值，提高可读性

					// 如果没有该分组，则初始化
					if (!groupedData.has(TreeTypeName)) {
						groupedData.set(TreeTypeName, {
							TreeType,
							APPType: appType,
							Node: [], // 初始化 Node 数组
						});
					}

					// 获取 IconApprove，default 为空数组
					const iconApprove = ds1Map.get(APPFunID) || [];

					// 将当前项添加到对应的 Node 中
					groupedData.get(TreeTypeName).Node.push({
						...item,
						IconApprove: iconApprove,
					});
				});

				// 从 Map 转换为数组并返回
				return Array.from(groupedData, ([treeTypeName, group]) => ({
					TreeTypeName: treeTypeName,
					...group,
				}));
			},

			// 初始化图表
			async initTabs() {
				await this.GetWaitData(); // 获取代办数据
				await this.getRealTimeData('本日');
				await this.getSalesVolume('本周');
				await this.getSaleProportion();
			},

			// 跳转当前菜单页面
			checkOutMenu(menu) {
				let that = this;
				let filterData = that.$store.state.APPModules.filter(item => item.ModuleName == menu.APPTypeName);

				// 持久化模块数据
				that.$store.commit('ChangeAndSetStateData', {
					Name1: 'ModuleInfo_All',
					data: this.organizedData,
					StorageName: 'ModuleInfo_All',
					StorageData: JSON.stringify(this.organizedData),
				});

				that.$store.commit('ChangeAndSetStateData', {
					Name1: 'Module_Tabbar',
					data: this.TabbarData,
					StorageName: 'Module_Tabbar',
					StorageData: JSON.stringify(this.TabbarData),
				});

				// 更新活动模块到 Vuex 存储
				that.$store.commit('ChangeAndSetStateData', {
					Name1: 'ActiveModule',
					data: filterData[0],
					StorageName: 'ActiveModule',
					StorageData: JSON.stringify(filterData[0]),
				});

				this.$store.commit('ChangeAndSetStateData', {
					Name1: 'Menu',
					data: menu
				});
				// 页面跳转待配置
				uni.navigateTo({
					url: menu.AP_Link
				})
			},

			// 切换分类
			changeTreeType(treeType, index) {
				let that = this;
				that.selectedTreeType = treeType;
				that.treeTypeIdx = index;
			},

			toggleShortcut(page) {
				if (!page.IsShortcut) {
					if (page.IsChecked) {
						page.IsChecked = false;
					} else {
						page.IsChecked = true;
					}
					this.$forceUpdate();
				}
			},

			// 快捷菜单初始化
			initShortcut() {
				let that = this;
				let modules = that.$store.state.APPModules;
				that.module = modules.find(item => item.ModuleID == that.currModuleID);
				let str = uni.getStorageSync('shortcuts' + that.currBoardID); // 获取缓存快捷菜单
				if (str) { // 存在快捷菜单缓存,则对比后更新
					let shortcuts = JSON.parse(str);
					let Menus1 = that.module.shortcuts.filter(item => item.IsShortcut && item.KanBanID == that
						.currBoardID); // 默认菜单整体替换
					let Menus2 = that.compareMenus(shortcuts, that.module.authPages); // 非默认菜单
					that.shortcuts = [...Menus1, ...Menus2];
					that.initTree(Menus2);
				} else { // 不存在则取后台默认快捷
					that.shortcuts = that.module.shortcuts.filter(item => item.IsShortcut && item.KanBanID == that
						.currBoardID);
				}


				if (that.shortcuts.length) {
					let filterData = that.$store.state.APPModules.filter(item => item.ModuleName == that.shortcuts[0]
						.APPTypeName);
					if (filterData.length) {
						that.initModule(filterData[0])
					}
				}
				that.persistShortcut(that.shortcuts);
			},

			// 保存快捷发起
			saveShortcut() {
				let that = this;
				let addPages = []; // 勾选页面
				let delPages = []; // 反选页面
				that.module.treeTypes.forEach(tree => {
					tree.pages.forEach(page => {
						let flag = that.shortcuts.some(item => item.APPFunID == page.APPFunID);
						if (!page.IsShortcut && !flag && page.IsChecked) { // 新增
							addPages.push(page);
						}
						if (!page.IsShortcut && flag && !page.IsChecked) { // 删除
							delPages.push(page);
						}
					})
				})
				// 最大可设置快捷方式数量
				let totalnums = that.shortcuts.length + addPages.length - delPages.length;
				if (totalnums > that.maxMenus) {
					uni.showToast({
						title: '超最大可设置数!',
					})
					that.initTree(that.shortcuts.filter(item => !item.IsShortcut));
					return;
				}
				delPages.forEach(item => {
					let idx = that.shortcuts.findIndex(sc => sc.APPFunID == item.APPFunID);
					that.shortcuts.splice(idx, 1);
				})
				that.shortcuts = [...that.shortcuts, ...addPages];
				that.persistShortcut(that.shortcuts);
				that.showMenuCfg = false;
				uni.showToast({
					title: '设置成功!',
					icon: 'success'
				})
			},

			// 比较缓存非默认快捷菜单并返回
			compareMenus(oldMenu, newMenu) {
				let menus = oldMenu.filter(item => !item.IsShortcut);
				menus.forEach((item, index) => {
					// 缓存非默认快捷菜单不存在于授权页面中则移除
					let flag = newMenu.some(m => m.APPFunID == item.APPFunID);
					if (!flag) {
						menus.splice(index, 1);
					}
				});
				return menus;
			},

			// 初始化选中状态(非默认快捷菜单部分)
			initTree(menus) {
				let that = this;
				// 更新非默认已有菜单为选中
				menus.forEach(menu => {
					let treeType = that.module.treeTypes.find(tree => tree.treeType == menu.TreeType);
					let page = treeType.pages.find(page => page.APPFunID == menu.APPFunID);
					page.IsChecked = true;
				})
				// 更新选中未保存为未选中
				that.module.treeTypes.forEach(tree => {
					tree.pages.forEach(item => {
						let flag = menus.some(menu => menu.APPFunID == item.APPFunID);
						if (!flag && !item.IsShortcut) {
							item.IsChecked = false;
						}
					})
				})
			},

			// 持久化快捷菜单
			persistShortcut(shortcuts) {
				let that = this;
				that.$store.commit('ChangeAndSetStateData', {
					Name1: 'shortcuts' + that.currBoardID,
					data: shortcuts,
					StorageName: 'shortcuts' + that.currBoardID,
					StorageData: JSON.stringify(shortcuts)
				});
			},

			// 显示弹窗
			showPopUp(type) {
				let that = this;
				if (type == 'menuConfig') {
					that.treeTypeIdx = 0;
					that.selectedTreeType = that.module.treeTypes[0];
					that.showMenuCfg = true;
				}
			},

			// 关闭弹窗
			closePopUp(type) {
				let that = this;
				if (type == 'menuConfig') {
					that.showMenuCfg = false;
					that.initTree(that.shortcuts.filter(item => !item.IsShortcut));
				}
			},

			handleClick_wait(data) {
				let newData = this.$utils.deepClone(data)

				newData['APFunName'] = '';
				newData['Para'] = '';

				let path = '';
				let moduleName = '';

				if (newData && newData['Url']) {
					const [urlPath, queryString] = newData['Url'].split('?');
					path = urlPath;

					if (queryString) {
						// 直接搜索并提取moduleName的值  
						const params = queryString.split('&');
						for (const param of params) {
							const [key, value] = param.split('=');
							if (key === 'moduleName') {
								moduleName = decodeURIComponent(value);
								break; // 找到后退出循环  
							}
						}
					}
				}
				newData['APFunName'] = moduleName;
				newData['Para'] = moduleName;

				this.$store.commit('ChangeAndSetStateData', {
					Name1: 'Menu',
					data: newData
				});

				let theType = this.waitActiveCurrent == 0 ? "wait" : "audit";
				uni.navigateTo({
					url: path + "?type=" + theType
				})

			},

			// 获取待办数据
			GetWaitData() {
				let that = this;

				that.Request.request('APP_GetToDoByKanBan', {
					KanBanID: that.currBoardID,
				}, (ret) => {
					if (ret.status == 200) {
						that.notApproveData = ret.data.ds;
						that.waitData = [...ret.data.ds1];

						// 默认初始展示代办
						that.waitDataShow = that.notApproveData;
					}
				}, (err) => {
					that.$utils.msg(JSON.stringify(err))
				})
			},

			// 获取实时数据
			getRealTimeData(name) {
				let that = this;
				const type = name === '本日' ? 'day' : name === '本月' ? 'month' : null;
				const dateRange = that.getTimeRange(type, 'yyyy-MM-dd');

				that.Request.request('PlatForm_StockNum', {
						FSDate: dateRange[0],
						FEDate: dateRange[1]
					}, function(res) {
						that.realTimeData = res.data.ds;
					},
					function(err) {}, that.Request.IPAgreement() + that.Request.serverIP() +
					'/Frame/SqlData', 1)
			},
			// 获取销量
			getSalesVolume(name) {
				let that = this;
				const type = name === '本周' ? 'week' : name === '本月' ? 'month' : name === '本年' ? 'year' :
					null;
				// const dateRange = that.getTimeRange(type, 'yyyy-MM-dd');	
				that.Request.request('PlatForm_CRKQty', {
						FType: type
					}, function(res) {
						let data = JSON.parse(JSON.stringify(res.data.ds));
						let newData = that.fillMissingTimeData(name, data);
						that.chart1Data = {
							categories: newData['name'],
							series: [{
								name: '入库数量',
								data: newData['Qty']
							}, {
								name: '出库数量',
								data: newData['Money']
							}]
						}
					},
					function(err) {}, that.Request.IPAgreement() + that.Request.serverIP() +
					'/Frame/SqlData', 1)
			},
			// 获取销售占比
			getSaleProportion() {
				let that = this;
				that.Request.request('PlatForm_KL', {}, function(res) {
						// console.log(res);
						let data = res.data.ds.map(item => {
							return {
								...item,
								value: item.rate
							}
						})
						that.chart2Data = {
							series: [{
								data: data
							}]
						}
					},
					function(err) {}, that.Request.IPAgreement() + that.Request.serverIP() +
					'/Frame/SqlData', 1)
			},
			// tab条件切换
			switchTab(switchType, item) {
				switch (switchType) {
					case 'TODO':
						// this.getTodoData(item.name);
						this.waitActiveCurrent = item.index;
						this.waitDataShow = item.name === '待办' ? this.notApproveData : this.waitData;

						this.$forceUpdate()
						break;
					case 'REALTIME':
						this.getRealTimeData(item.name);
						break;
					case 'SALE':
						this.getSalesVolume(item.name);
						break;
					default:
						break;
				}
			},
			// 获取日期区间
			getTimeRange(type, format) { // 传入字段，返回时间范围
				var now = new Date();
				var year = now.getFullYear();
				var month = now.getMonth() + 1; // 月份从0开始，所以需要加1
				var day = now.getDate();
				var weekDay = now.getDay(); // 0表示周日，1表示周一，以此类推

				switch (type) {
					case 'day':
						return [this.formatDate(new Date(year, month - 1, day, 0, 0, 0), format), this.formatDate(new Date(
							year, month - 1, day, 23, 59, 59), format)];
					case 'week':
						var startOfWeek = new Date(year, month - 1, day - weekDay, 0, 0, 0);
						var endOfWeek = new Date(year, month - 1, day + (6 - weekDay), 23, 59, 59);
						return [this.formatDate(startOfWeek, format), this.formatDate(endOfWeek, format)];
					case 'month':
						return [this.formatDate(new Date(year, month - 1, 1, 0, 0, 0), format), this.formatDate(new Date(
							year, month, 0, 23, 59, 59), format)];
					case 'year':
						return [this.formatDate(new Date(year, 0, 1, 0, 0, 0), format), this.formatDate(new Date(year, 11,
							31, 23, 59, 59), format)];
					default:
						throw new Error('Invalid type');
				}
			},
			// 日期格式化
			formatDate(date, format) {
				var map = {
					'M': date.getMonth() + 1, // 月份
					'd': date.getDate(), // 日
					'h': date.getHours(), // 小时
					'm': date.getMinutes(), // 分
					's': date.getSeconds(), // 秒
					'q': Math.floor((date.getMonth() + 3) / 3), // 季度
					'S': date.getMilliseconds() // 毫秒
				};
				format = format.replace(/([yMdhmsqS])+/g, function(all, t) {
					var v = map[t];
					if (v !== undefined) {
						if (all.length > 1) {
							v = '0' + v;
							v = v.substr(v.length - 2);
						}
						return v;
					} else if (t === 'y') {
						return (date.getFullYear() + '').substr(4 - all.length);
					}
					return all;
				});
				return format;
			},
			fillMissingTimeData(timeRange, dataArray) {
				let result = {
					name: [],
					Qty: [],
					Money: []
				};

				// 根据时间范围初始化 result 数组
				let currentDate = new Date();
				if (timeRange === '本周') {
					let startOfWeek = currentDate.getDate() - currentDate.getDay();
					for (let i = startOfWeek; i <= currentDate.getDate(); i++) {
						let date = new Date(currentDate.getFullYear(), currentDate.getMonth(), i);
						let formattedDate = (date.getMonth() + 1).toString().padStart(2, '0') + '-' + date.getDate()
							.toString().padStart(2, '0');
						let existingItem = dataArray.find(item => item.name === formattedDate);
						if (existingItem) {
							result.name.push(existingItem.name);
							result.Qty.push(existingItem.RKQty);
							result.Money.push(existingItem.CKQty);
						} else {
							result.name.push(formattedDate);
							result.Qty.push(0);
							result.Money.push(0);
						}
					}
				} else if (timeRange === '本月') {
					for (let i = 1; i <= currentDate.getDate(); i++) {
						let date = new Date(currentDate.getFullYear(), currentDate.getMonth(), i);
						let formattedDate = (date.getMonth() + 1).toString().padStart(2, '0') + '-' + date.getDate()
							.toString().padStart(2, '0');
						let existingItem = dataArray.find(item => item.name === formattedDate);
						if (existingItem) {
							result.name.push(existingItem.name);
							result.Qty.push(existingItem.RKQty);
							result.Money.push(existingItem.CKQty);
						} else {
							result.name.push(formattedDate);
							result.Qty.push(0);
							result.Money.push(0);
						}
					}
				} else if (timeRange === '本年') {
					for (let i = 0; i <= currentDate.getMonth(); i++) {
						let date = new Date(currentDate.getFullYear(), i, 1);
						let formattedDate = i + 1;
						let existingItem = dataArray.find(item => item.name === formattedDate);
						if (existingItem) {
							result.name.push(existingItem.name + '月');
							result.Qty.push(existingItem.RKQty);
							result.Money.push(existingItem.CKQty);
						} else {
							result.name.push(formattedDate + '月');
							result.Qty.push(0);
							result.Money.push(0);
						}
					}
				}

				return result;
			}
		}
	}
</script>

<style lang="scss" scoped>
	$h-padding: 5px;
	$v-padding: 10px;
	$radius: 5px;

	.rtTop {
		display: flex;
		justify-content: center;
		align-items: center;
		padding-top: 20rpx 0;
		font-size: 18px;
		font-weight: 500;

		&-left {
			display: flex;
			justify-content: center;
			align-item: center;
			color: rgba(108, 148, 255, 1);
			background: rgba(108, 148, 255, .11);
			width: 36px;
			height: 36px;
			line-height: 36px;
			border-radius: 18px;
		}

		&-right {
			margin-left: 20px;
		}
	}

	.rtBot {
		display: flex;
		justify-content: space-between;
		font-size: 14px;
		color: #909399;
		margin-top: 10rpx;

		&-right {
			margin-left: 20rpx;
		}
	}

	// 待办
	.todoTop {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		width: 100%;
		padding: 0 20rpx;
		font-weight: 500;

		&-text {
			font-size: 18px;
			margin-left: 20rpx;
		}
	}

	.todoBot {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		font-size: 14px;
		color: #909399;
		padding: 10rpx 20rpx 20rpx;
		width: 100%;
	}

	.charts-box {
		width: 100%;
		height: 300px;
	}

	//设置轮播的指示点大小
	.swiper {
		height: 160px;

		/deep/ .uni-swiper-dots {
			// 指示点整个区域
			bottom: 10rpx;
		}

		/deep/ .uni-swiper-dot {
			// 指示点元素默认样式
			width: 10rpx;
			height: 6rpx;
			border-radius: 4rpx;
		}

		/deep/ .uni-swiper-dot-active {
			// 指示点元素激活（当前选中）状态样式
			width: 20rpx;
			background: #51d0d0;
		}
	}

	// 快捷菜单宫格
	.grid-text {
		font-size: 14px;
		color: #909399;
		padding: 5px 0 10px 0;
		/* #ifndef APP-PLUS */
		box-sizing: border-box;
		/* #endif */
	}

	// 待办/实时数据横向滚动
	.scrollWrap {
		display: flex;
		flex-direction: column;
		flex-wrap: wrap;
		max-height: 180px;
		overflow-y: hidden;
		overflow-x: auto;
		row-gap: 3px;
		column-gap: 3px;

		&-item {
			width: 35vw;
			height: 80px;
			display: flex;
			flex-direction: column;
			background: linear-gradient(to bottom right, #F6F6F6, #FFFFFF);
			border-radius: 5px;
			padding: 5px 10px;
			justify-content: center;
			align-items: center;
		}
	}

	// 快捷菜单弹窗
	.shortcut {
		display: flex;
		flex-direction: column;
		height: 80vh;

		&-content {
			display: flex;
			flex: 1;
			padding: $v-padding $h-padding;

			.left_wrap {
				display: flex;
				flex-direction: column;
				width: 180rpx;

				.leftItem {
					display: flex;
					justify-content: center;
					align-items: center;
					height: 60rpx;
					border-radius: $radius;
				}

				.leftItem.on {
					background-color: $main-background-color;
					color: #ffffff;
				}
			}

			.right_wrap {
				display: flex;
				flex-direction: column;
				flex: 1;
				height: calc(80vh - 44px);
				overflow-y: auto;

				.rightItem {
					display: flex;
					justify-content: flex-start;
					align-items: center;
					font-size: 28rpx;
					margin-left: $h-padding;
				}

				.rightItem.on {
					background-color: $main-background-color;
					color: #ffffff;
				}
			}
		}

		&-bottom {
			display: flex;
			justify-content: center;
			align-items: center;
			position: fixed;
			width: 100%;
			height: 100rpx;
			padding: $v-padding $h-padding;
			left: 0;
			bottom: calc(100rpx + env(safe-area-inset-bottom) / 2);
		}
	}

	.boardWrap {
		display: flex;
		flex-direction: column;

		.commonBox {
			display: flex;
			flex-direction: column;
			padding: $v-padding $h-padding;
			background-color: #ffffff;
			margin-bottom: $v-padding;
			border-radius: $radius;

			&-title {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 $h-padding $v-padding $h-padding;

				&-left {
					display: flex;
					justify-content: flex-start;
					align-items: center;
					width: 150rpx;
					font-size: 14px;
					font-weight: 500;
				}

				&-right {
					display: flex;
					justify-content: flex-end;
					align-items: center;
					width: 100rpx;
				}
			}

			&-content {
				display: flex;
				flex-direction: column;
			}
		}

	}
</style>